package com.example.teamtribe.main.club.estimate;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.teamtribe.R;
import com.example.teamtribe.database.Estimate;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class EstimateListAdapter extends RecyclerView.Adapter<EstimateListAdapter.ViewHolder> {

    private List<Estimate> estimates;

    public EstimateListAdapter(List<Estimate> estimates) {
        this.estimates = estimates;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_estimate, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Estimate estimate = estimates.get(position);
        holder.tvName.setText(estimate.getName());
        double grade = 0;
        for (int i : estimate.getGrade()) {
            grade += i;
        }
        grade /= estimate.getGrade().size();
        holder.tvGrade.setText("综合评分：" + grade);
        holder.tvSuggest.setText(estimate.getSuggest());
    }

    @Override
    public int getItemCount() {
        return estimates.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_grade)
        TextView tvGrade;
        @BindView(R.id.tv_suggest)
        TextView tvSuggest;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
